package com.linxianqin.mapstruct.more2one;


import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

/**
 * 功能描述：
 *
 * @author lxq
 * @version 1.00
 * @Date 2020/12/14
 */
@Mapper
public interface more2oneConvert {
    more2oneConvert INSTANCE = Mappers.getMapper(more2oneConvert.class);
    /**
     * Result与Student合并为StuAndRe
     * */
    @Mappings(value = {
            @Mapping(source = "result.name",target = "RName"),
            @Mapping(source = "result.type",target = "RType"),
            @Mapping(source = "result.days",target = "RDays"),
            @Mapping(source = "student.id",target = "SId"),
            @Mapping(source = "student.name", target = "SName"),
            // constant注入产量值
            @Mapping(target = "score", constant = "80"),
            @Mapping(target = "level", constant = "C4"),
            //忽略test属性
            @Mapping(target = "test", ignore = true)
    })
    StuAndRe ResStu2StuAndRe(Result result,Student student);

    /**
     * 三个实体合并属性
     * @param result :
     * @param student :
     * @param v1 :
     * @param v2 :
     * @return demo2.StuAndRe
     * @author wangshilei
     * @date 2020/10/12 10:29
     **/
    @InheritConfiguration(name = "ResStu2StuAndRe")
    @Mappings(value = {
            @Mapping( source = "v1",target = "score"),
            @Mapping( source = "v2",target = "level")
    })
    StuAndRe AllString2StuAndRe(Result result,Student student,String v1,String v2);

    /**
     * Result、SC与Student合并为StuAndRe
     **/
    @Mappings(value = {
            @Mapping(source = "result.name",target = "RName"),
            @Mapping(source = "result.type",target = "RType"),
            @Mapping(source = "result.days",target = "RDays"),
            @Mapping(source = "student.id",target = "SId"),
            @Mapping(source = "student.name", target = "SName"),
            // 设置默认值
            @Mapping(source = "sc.test",target = "test",defaultValue = "this is test")
    })
    StuAndRe All2StuAndRe(Result result,Student student,SC sc);

    /**
     * 跟新bean，@MappingTarget后面的对象不变**/
    @InheritConfiguration(name = "All2StuAndRe")
    void update(@MappingTarget StuAndRe stuAndRe, SC sc);

    /**
     * Result与字符串合并为StuAndRe
     **/
    @Mappings(value = {
            @Mapping(source = "result.name",target = "RName"),
            @Mapping(source = "result.type",target = "RType"),
            @Mapping(source = "result.days",target = "RDays"),
            @Mapping(source = "ids",target = "SId"),
            @Mapping(source = "names", target = "SName"),
    })
    StuAndRe Result2StuAndRe(Result result,String ids,String names);

}
